import { Component, OnInit } from '@angular/core';
import {ExceptionService} from "../exception.service";
import {ActivatedRoute} from "@angular/router";
import {ResponseUtil} from "../../../../util/response-util";
import {MsgResult} from "../../../../models/msg-result";
import {MsgConstants} from "../../../../constants/constants";
import {OneDialogService} from "../../../../widgets/one-dialog/one-dialog.service";
import {Exception} from "../exception";

@Component({
  selector: 'app-exception-detail',
  templateUrl: './exception-detail.component.html',
  styleUrls: ['./exception-detail.component.css']
})
export class ExceptionDetailComponent implements OnInit {

  exceptionLog :Exception;

  constructor(
    private route:ActivatedRoute,
    private responseUtil : ResponseUtil,
    private dialogService: OneDialogService,
    private exceptionService : ExceptionService
  ) {
    this.initObj();
  }

  ngOnInit() {
    this.getExceptionLogDetail();
  }

  getExceptionLogDetail(){
    let id = this.route.snapshot.params['id'];
    this.exceptionService.exceptionLogDetails(id).subscribe(
      result => this.responseUtil.success(result,this.processExceptionLogResult),
      error => this.responseUtil.error(error)
    );
  }

  private processExceptionLogResult =(result:MsgResult)=>{
    if(result && result.code == MsgConstants.MSG_CODE_OK){
      this.exceptionLog = result.data;
    }
    if(result && result.code != MsgConstants.MSG_CODE_OK){
    this.dialogService.error(result.message);
    }
  }

  initObj(){
    this.exceptionLog =new Exception;
  }

}
